<template>
  <div class="exam" v-loading="loadingS">
    <el-form style="padding-right: 20px" v-model="formPass" ref="formPass">
      <el-form-item label="内容：" prop="text">
        <el-input
          type="textarea"
          v-model="form.text"
          disabled="disabled"
          autocomplete="off"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="处理说明：" prop="auditExplain">
        <el-input
          type="textarea"
          v-model="form.auditExplain"
          autocomplete="off"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item style="width: 100%" label="附件说明" prop="imgs">
        <div class="row">
          <el-image
            @click="deleteImg(item, index)"
            v-for="(item, index) in form.replyImgs"
            :key="index"
            :src="getItemPhoto(item)"
            class="el-upload--picture-card mr20"
          ></el-image>
          <el-upload
            ref="uploadImg"
            :show-file-list="false"
            action="#"
            list-type="picture-card"
            :http-request="handleUpLoad"
          >
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <i style="color: red" class="tishi"> *上传小于10MB图片</i>
        </div>
      </el-form-item>
    </el-form>
    <el-button type="success" @click="handleSuccess">点击处理</el-button>
    <!-- <el-button type="danger" @click="handleFail">不能处理</el-button> -->
  </div>
</template>

<script>
import Trans from "@/components/img/transform";
export default {
  components: {
    Trans,
  },
  props: {
    /* 表单数据 */
    formPass: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      loadingS: false,
      form: {
        _id: "",
        auditType: "", //是否通过
        text: this.formPass.text, // 内容
        auditExplain:"通过",//审核说明
        replyImgs:this.formPass.replyImgs || []

      },
      listVill: "",
    };
  },
  methods: {
    deleteImg(item, index) {
      this.$confirm("确认删除此照片吗？", "提示", {}).then(() => {
        this.form.replyImgs.splice(index, 1);
      });
    },
    async handleUpLoad(param, fileList) {
      var imgup = "";
      await this.getBase64(param.file).then((res) => {
        imgup = res;
      });
      var paramd = {
        img: imgup,
      };
      this.$api.imgAdd
        .addimgPer(paramd)
        .then((res) => {
          if (res.code == 0) {
            this.form.replyImgs.push(res.id);
          } else {
            this.$message({
              message: res.msg,
              type: "info",
            });
          }
        })
        .catch((err) => {
          this.$message({
            message: err,
            type: "info",
          });
        });
    },
     // 拼接图片
    getItemPhoto(id) {
      var url = this.global.baseUrlImage + "avatar/" + id;
      return url;
    },
    handleAvatarSuccess(res, file) {
      this.addImgUrl = URL.createObjectURL(file.raw);
    },
    beforeRead(file) {
      let that = this;
      return new Promise((resolve) => {
        fileUtils.getOrientation(file).then((orient) => {
          let reader = new FileReader();
          let img = new Image();
          reader.onload = (e) => {
            img.src = e.target.result;
            img.onload = async function () {
              let width = 600,
                height = 600 * (img.height / img.width);
              const data = await fileUtils.rotateImage(
                img,
                width,
                height,
                orient
              );
              const newFile = await fileUtils.dataURLtoFile(data, file.name);
              resolve(that.upLoad(newFile));
            };
          };
          reader.readAsDataURL(file);
        });
      });
    },
    //图片处理
    getBase64(file) {
      return new Promise(function (resolve, reject) {
        let reader = new FileReader();
        let imgResult = "";
        reader.readAsDataURL(file);
        reader.onload = function () {
          imgResult = reader.result;
        };
        reader.onerror = function (error) {
          reject(error);
        };
        reader.onloadend = function () {
          resolve(imgResult);
        };
      });
    },
   
    // 审核通过
    handleSuccess() {
      this.formPass.auditType = 1;

      this.formPass.remarks = this.form.text;
      this.formPass.replyImgs = this.form.replyImgs;
       let params = {
         remarks:this.form.auditExplain,
         replyImgs:this.form.replyImgs,
         WID:this.formPass.WID,
         auditType:1

       };
      
      let param = JSON.stringify(params);
      this.loadingS = true;
      this.$api.wxNotic.sys_wish_examine(param).then((res) => {
        if (res.code == 0) {
          this.loadingS = false;
          this.$message({
            type: "success",
            message: "审核通过",
          });

          this.$emit("getexam");
        } else {
          this.loadingS = false;
          this.$message({
            message: "操作失败, " + res.msg,
            type: "error",
          })
            .catch((err) => {
              this.loadingS = false;
            })
            .finally(() => {
              this.loadingS = false;
            });
          this.$emit("getexam");
        }
      });
    },
    //审核不通过
    handleFail() {
      this.formPass.auditType = 0;
      let param = JSON.stringify(this.formPass);
      this.loadingS = true;
      this.$api.personPass.personAudit(param).then((res) => {
        if (res.code == 0) {
          this.loadingS = false;
          this.$message({
            type: "success",
            message: "审核不通过",
          });
          this.$emit("getexam");
        } else {
          this.loadingS = false;
          this.$message({
            message: "操作失败, " + res.msg,
            type: "error",
          });
          this.$emit("getexam");
        }
      });
    },
  },
  mounted() {},
};
</script>

<style>
</style>
